import { GameMapBase } from '@/assets/map/GameMapBase.js'
import { PlayerFactory } from '@/assets/player/PlayerFactory.js'

/**
 * 人机对战游戏地图类，继承自GameMap基类
 * 负责管理人机对战游戏模式下的地图绘制和更新
 */
export class PvEGameMap extends GameMapBase {
    /**
     * 构造函数，初始化单人游戏地图
     * @param {CanvasRenderingContext2D} ctx - 画布2D渲染上下文
     * @param {string} difficulty - 游戏难度，默认为normal'
     */
    constructor(ctx, difficulty = 'normal') {
        super(ctx)
        this.difficulty = difficulty
        this.initialize_players()
    }

    // 根据难度级别返回AI玩家数量
    get_ai_count_by_difficulty(difficulty) {
        switch (difficulty) {
            case 'easy':
                return 3
            case 'normal':
                return 5
            case 'hard':
                return 5
            case 'expert':
                return 7
            default:
                return 5
        }
    }

    // 初始化玩家
    initialize_players() {
        // 添加自己
        const myInfo = {
            x: this.width / 2,
            y: this.height / 2,
            radius: this.height * this.sizeConfig.playerRadius,
            color: 'white',
            speed: this.height * this.sizeConfig.playerSpeed,
            hp: 100,
            role: 'me',
            photo: '',
            username: '',
            userId: '',
        }
        this.players.push(PlayerFactory.createPlayer(this, myInfo))

        // 添加AI玩家
        const aiCount = this.get_ai_count_by_difficulty(this.difficulty)
        for (let i = 0; i < aiCount; i++) {
            const foeInfo = {
                x: this.width / 2,
                y: this.height / 2,
                radius: this.height * this.sizeConfig.playerRadius,
                color: this.get_random_color(),
                speed: this.height * this.sizeConfig.playerSpeed,
                hp: 100,
                role: 'AI',
                photo: '',
                username: 'AI ' + i,
                userId: i,
            }
            this.players.push(PlayerFactory.createPlayer(this, foeInfo))
        }
    }

    start() {
        console.log(this.difficulty)
    }
}
